package com.hjb.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hjb.entity.User;
import com.hjb.mapper.UserMapper;
import com.hjb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author JianBinHuang
 * @Description
 * @Date 2021/9/9 19:04
 */
@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo<User> getUserPage(String currentPage) {
        //设置当前页为1
        int current=1;
        //设置最大页数为5页
        int pageSize=5;
        if(currentPage!=null){
            current=Integer.parseInt(currentPage);
        }
        //设置分页参数
        PageHelper.startPage(current,pageSize);
        //得到有分页信息的结合，因为这个集合可以转成Page对象
        List<User> userList=userMapper.queryUserList();
        return new PageInfo<>(userList);
    }

    @Override
    public User queryUserById(int id) {
        return userMapper.queryUserById(id);
    }

    @Override
    public List<User> queryUserList() {
        return userMapper.queryUserList();
    }

    @Override
    public void addUsers(User user) {
        userMapper.addUsers(user);
    }

    @Override
    public void updateUsers(User user) {
        userMapper.updateUsers(user);
    }

    @Override
    public void deleteById(int id) {
        userMapper.deleteById(id);
    }

    @Override
    public List<User> queryVagueByName(User user) {
        return userMapper.queryVagueByName(user);
    }
}
